<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>API_MANAGER</title>
    
</head>

<body>
<jsp:include page="/common/head.jsp"></jsp:include>
<div class="container">
	<table id="managerList" style="width:640px;"></table>
	<div id="toolbar">
		<c:if test="${sessionScope.user.issuper == 1 }">
		<a href="javascript:void(0)" id="add1" class="easyui-linkbutton">添加</a>
		</c:if>
		<input class="easyui-searchbox" style="width:150px" id="ss" />
	</div>
	
	<div id="w" class="easyui-window" title="添加项目" data-options="iconCls:'icon-save'" style="width:500px;height:350px;padding:5px;top:20px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<div style="margin-bottom:20px">
					<div>名称:</div>
					<input class="easyui-textbox" type="text" id="cname" name="cname" style="width:100%;height:32px">
				</div>
				<div style="margin-bottom:20px">
					<div>描述:</div>
					<input class="easyui-textbox" type="text" id="cdesc" name="cdesc" style="width:100%;height:32px">
				</div>
				<div style="margin-bottom:20px">
					<div style="color:red" id="message"></div>
				</div>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="ok1" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:80px">确定</a>
				<a id="cancel1" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" style="width:80px">取消</a>
			</div>
		</div>
	</div>
	
	<div id="e" class="easyui-window" title="编辑项目" data-options="iconCls:'icon-save'" style="width:500px;height:350px;padding:5px;top:20px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<div style="margin-bottom:20px">
					<div>名称:</div>
					<input type="hidden" id="aid" />
					<input class="easyui-textbox" type="text" id="cname2" name="cname" style="width:100%;height:32px">
				</div>
				<div style="margin-bottom:20px">
					<div>描述:</div>
					<input class="easyui-textbox" type="text" id="cdesc2" name="cdesc" style="width:100%;height:32px">
				</div>
				<div style="margin-bottom:20px">
					<div style="color:red" id="message2"></div>
				</div>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="ok2" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:80px">确定</a>
				<a id="cancel2" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" style="width:80px">取消</a>
			</div>
		</div>
	</div>
	
</div>

<script type="text/javascript">
$(document).ready(function(){
	$('#w').window('close');
	$('#e').window('close');
	$("#managerList").datagrid({
		url:"<%=path%>/projAction!list",
		columns:[[ 
			{field:'cname',title:'项目',width:100},
			{field:'cdesc',title:'描述',width:200},
			{field:'addtime',title:'添加时间',width:100,formatter:function(value){
				return $.myTime.UnixToDate(value);
			}},
			{field:'aid',title:'操作',width:160,formatter:function(value){
				return "<a class=\"edit1\" href=\"javascript:void(0)\" data-id='"+value+"' >编辑</a>"
				+ " <a class=\"delete1\" href=\"javascript:void(0)\" data-id='"+value+"'  >删除</a>"
				+ " <a href=\"<%=path%>/cateAction!cate?cate.pid="+value+"\" >模块</a>"
				+ " <a href=\"<%=path%>/projAction!gotoApi?aid="+value+"\" >接口报表</a>";
			}},
		]],
		toolbar:'#toolbar',  //表格菜单
		loadMsg:'数据加载中请稍后……', //加载提示
		pagination:true, //显示分页工具栏
		rownumbers:true, //显示行号列
		//singleSelect:false,//是允许选择一行
		//queryParams:{   
			//在请求数据是发送的额外参数，如果没有则不用谢
			//'proj.cname':$("#ss").val()
		//},
		height:'350px',
		onLoadSuccess:function(){
			$(".pagination-page-list").css('display','none');
			$(".pagination-btn-separator").css('display','none');
			var url_new = $('#managerList').datagrid('options').url;
			if(url_new == '<%=path%>/projAction!list'){
				$("#ss").textbox('clear');
			}
			if($("#sid").val() == 0){
				$(".edit1").css('display','none');
				$(".delete1").css('display','none');
			}
			$(".delete1").bind('click',function(){
				var deleteId = $(this).attr("data-id");
				$.messager.confirm('删除提示', '确定要删除该条数据吗？', function(r){
					if (r){
						$.post("<%=path%>/projAction!destroy",{'deleteId':deleteId},function(result){
						    if(result == 'success'){
						    	$.messager.show({
									title:'操作提示',
									msg:'删除操作成功',
									showType:'show',
									style:{
										right:'',
										top:document.body.scrollTop+document.documentElement.scrollTop,
										bottom:''
									}
								});
						    }
						    $("#managerList").datagrid('reload'); 
						},"text");
					}
				});
				return false;
			});
			
			$(".edit1").bind('click',function(){
				var deleteId = $(this).attr("data-id");
				$.post("<%=path%>/projAction!edit",{'deleteId':deleteId},function(p){
					$('#e').window('open');
					$("#cname2").textbox('setValue',p.result.cname);
					$("#cdesc2").textbox('setValue',p.result.cdesc);
					$("#aid").val(p.result.aid);
					$("#message2").html('');
				},"json");
			});
		}
	});
	
	$("#add1").click(function(){
		$("#cname").textbox('clear');
		$("#cdesc").textbox('clear');
		$("#message").html("");
		$('#w').window('open');
	});
	
	$("#ok1").click(function(){
		var cname = $("#cname").val();
		var cdesc = $("#cdesc").val();
		if(cname == ''){
			$("#message").html('项目名称不能为空！');
			return false;
		}
		$.post("<%=path%>/projAction!insert",{'proj.cname':cname,'proj.cdesc':cdesc},function(r){
			if(r == 'success'){
				$.messager.show({
					title:'操作提示',
					msg:'添加操作成功',
					showType:'show',
					style:{
						right:'',
						top:document.body.scrollTop+document.documentElement.scrollTop,
						bottom:''
					}
				});
			    $('#w').window('close');
			   	$("#managerList").datagrid('reload'); 
		    }else{
		    	$("#message").html(r);
		    }
		},"text");
	});
	
	$("#cancel1").click(function(){
		$('#w').window('close');
	});
	
	$("#cancel2").click(function(){
		$('#e').window('close');
	});
	
	$("#ok2").click(function(){
		var cname = $("#cname2").val();
		var cdesc = $("#cdesc2").val();
		var aid = $("#aid").val();
		if(cname == ''){
			$("#message2").html('项目名称不能为空！');
			return false;
		}
		$.post("<%=path%>/projAction!update",{'proj.aid':aid,'proj.cname':cname,'proj.cdesc':cdesc},function(r){
			if(r == 'success'){
				$.messager.show({
					title:'操作提示',
					msg:'编辑操作成功',
					showType:'show',
					style:{
						right:'',
						top:document.body.scrollTop+document.documentElement.scrollTop,
						bottom:''
					}
				});
			    $('#e').window('close');
			   	$("#managerList").datagrid('reload'); 
		    }else{
		    	$("#message2").html(r);
		    }
		},"text");
	});
	
	$('#ss').searchbox({ 
		width:200, 
		searcher:function(){ 
			var url_new = $('#managerList').datagrid('options').url;  
			url_new = '<%=path%>/projAction!list?proj.cname='+$("#ss").val();  
	        $('#managerList').datagrid('options').url=url_new;  
			$("#managerList").datagrid('reload'); 
		}
	}); 

});
</script>
</body>
</html>